<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
</head>
<body>
<div align="center" style="padding-top: 100px">
<div class="layui-form" style="width: 400px">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名：</label>
        <div class="layui-input-block">
            <input type="text" name="userName" required  lay-verify="required" autocomplete="off" class="layui-input" lay-filter="user" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密&nbsp;&nbsp;&nbsp;&nbsp;码：</label>
        <div class="layui-input-block">
            <input type="password" name="password" required  lay-verify="required"  autocomplete="off" class="layui-input" lay-filter="user" />
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">登录</button>
        </div>
    </div>
</div>
</div>
<script src="/layui/layui.js"></script>
<script th:inline="javascript">
    layui.use(['form','table','layer'], function() {
        var form = layui.form;
        var $ = layui.jquery;
        form.render({});
        form.on('submit(formDemo)', function(data){
            $.ajax({
                url:'/login',
                type:'post',
                data:JSON.stringify(data.field),
                contentType: "application/json;charset=utf-8",
                dataType:'json',
                success:function(data){
                    if(data.code == 500){
                        layer.msg(data.msg,{icon: 5});//失败的表情
                        return;
                    }else{
                        layer.msg(data.msg, {
                            icon: 6,//成功的表情
                            time: 1000 //1秒关闭（如果不配置，默认是3秒）
                        }, function(){
                            if (data.data.userType == 0)  window.location="/kf/manage";
                            else if (data.data.userType == -1) window.location="/admin/manage";
                        });
                    }
                },
                complete: function () {
                    layer.close(this.layerIndex);

                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        }
    );
</script>

</body>
</html>